package com.tuanbiao.models.action;

import androidx.annotation.NonNull;

import com.hzjq.data.callback.HttpCallback;
import com.hzjq.data.hzjq.entity.UserEntity;
import com.hzjq.lib.BlastKool;
import com.hzjq.lib.loader.QuickKool;
import com.tuanbiao.data.callback.OnBaseResultCallback;

import timber.log.Timber;

/**
 * @author abiao
 * @since 2022/5/7 9:41
 */
public interface LoginAction {
    default void startLoginCheck() {
        BlastKool.Companion.loader().startLoginCheck();
    }

    default void stopLoginCheck() {
        BlastKool.Companion.loader().stopLoginCheck();
    }

    default void login(String idCard, String password, OnBaseResultCallback<UserEntity> callback) {
        Timber.i("login");
        QuickKool.Companion.getKool().login(idCard, password, true, new HttpCallback<UserEntity>() {
            @Override
            public void onSuccess(UserEntity userEntity) {
                Timber.i("login#success");
                callback.onSuccess(userEntity);
                callback.onFinish();
            }

            @Override
            public void onFailed(@NonNull String s) {
                Timber.i("login#failed" + s);
                callback.onFailed(s);
                callback.onFinish();
            }
        });
    }

    default void logout() {
        BlastKool.Companion.loader().exitLogin();
    }

    default void offlineRegister(String idCard, String name, String password, String companyName
            , String companyCode, String createCompany, String blastCode,OnBaseResultCallback<UserEntity> callback) {
        BlastKool.Companion.loader().quick().register(companyCode, companyName, createCompany, blastCode, idCard, password, name, new HttpCallback<UserEntity>() {
            @Override
            public void onSuccess(UserEntity userEntity) {
                callback.onSuccess(userEntity);
                callback.onFinish();
            }

            @Override
            public void onFailed(@NonNull String s) {
                callback.onFailed(s);
                callback.onFinish();
            }
        });
    }
}
